var nrc = require('node-run-cmd');

function callback(data) {
    console.log(data)

    var reg = /time=(.+) bitrate/;
    let result = reg.exec(data);
    if (result && result.length > 1) {
        let curTime = result[1];
        console.log("format : [" + curTime + "]")
    }
}

filePath = "D:\\hls_genrate\\my_genrator\\res\\sahar 1.mp4";
out = "D:\\hls_genrate\\my_genrator\\out\\1\\";

let cmd = 'ffmpeg -y -i "' + filePath + '" -f hls -hls_time 10 -segment_format mpegts -segment_time 10 -hls_time 10 -bsf:v h264_mp4toannexb -map 0 -hls_list_size 0 -c:v libx264 ' + out + '/index.m3u8';

function onCompleteCmd(){
    console.log("================ complete !")
}

console.log("start --------------------")
nrc.run(cmd, {onData: callback, onError: callback,onDone:onCompleteCmd});

